<div class="right_side_operate_area">
	<div class="right_side_title left">
	</div>
    <div class="right item_add_btn">
    <?php 
    	$str_title=__("Add",true);
		if($id){
			$str_title=__("Edit",true);
		}
		echo $html->link(__("Cancel",true).$str_title,"/types/talstack/");
    ?>
    </div>
    <div class="clear"></div>
</div>
<div class="right_side_scollbar"> 
    <div class="detail_info_panel">
		<?php echo $form->create('types',array('url'=>'edittalstack','type'=>'post','onsubmit'=>'return checksave()'));?>			    
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left">项目名称：</div>
			    <div class="form_right_e_input left"><?php echo $form->text('Talstack.tname',array("maxlength"=>"100","onkeypress"=>"TextValidate()"));?>
			    </div>			  
				<div id='telstacktnamemessage' style='display:none;' class="error_message">请输入项目名称</div>
				<div id='pname' style='display:none;'><?php echo $form->value('Talstack.tname')?></div>
			</div>
		</div>
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left">主管部门：</div>
			    <div class="form_right_e_input left">
			    <?php $selecttalstacktype=$form->value("Talstack.gov"); ?>
			    <?php echo $form->select('Talstack.gov',$talstacktype, $selecttalstacktype, null,null);?>			    
			    </div>
			    <div id='talstacktypemessage' style='display:none;' class="error_message">请选择主管部门</div>
			</div>
		</div>
		<div class="details_item_line">
			<div class="details_item">
			    <div class="form_left_title left">政策：</div>
			    <div class="form_right_e_input left">
			    	<?php echo $form->textarea('Talstack.desc');?>
			    </div>			  
			</div>			
		</div>
		<?php for($i=0;$i<3;$i++){ ?>
		<div class="details_item_line">
			<div class="sub_class_drop_arrow"></div>
			<div class="details_item sub_class_bg">
				<div class="details_item">
					<div class="details_item_line">
				    	<div class="form_left_title left">二级项目：</div>
				   		<div class="form_right_e_input left">
				   		<?php 
				   		$tname="";
				   		$tid="";
				   		if($objsubtype){
				   			if($i<count($objsubtype)){
				   				$tname=$objsubtype[$i]["Talstack"]["tname"];
				   				$tid=$objsubtype[$i]["Talstack"]["id"];
				   			}
				   		}
				   		echo $form->text('Talstack.'.$i.'.tname',array("maxlength"=>"100","onkeypress"=>"TextValidate()","value"=>$tname));
				   		echo $form->hidden('Talstack.'.$i.'.id',array("value"=>$tid));
				   		?>		   		
				   		</div>			     
				    </div>
				    <div class="details_item_line talsubname"  id='stackstnamemessage<?php echo $i?>' >
				    	<div class="sub_class_drop_arrow"></div>
				    	<div class="details_item sub_class_bg">		
				    		 <?php 
				    		 $subtextcount=1;
				    		 $subcount=0;
				    		 if($i<count($objsubtypes)){
					   			$subcount=count($objsubtypes[$i]);
					   		 }
				    		 if($subcount>1){
					   			$subtextcount=$subcount;
					   		 }
				    		 for($j=0;$j<$subtextcount;$j++){?>
					    		 <div class="details_item_line">
							    	<div class="form_left_title left">三级项目：</div>
							   		<div class="form_right_e_input left">
							   			<?php 
								   		$subtname="";
								   		$subtid="";
								   		if($objsubtypes){
								   			$objtypes=array();
								   			if($i<count($objsubtypes)){
									   			$objtypes=$objsubtypes[$i];
									   		}
									   		if($objtypes){
									   			if($j<count($objtypes)){
									   				$subtname=$objtypes[$j]["Talstack"]["tname"];
									   				$subtid=$objtypes[$j]["Talstack"]["id"];
									   			}
									   		}
								   		}
								   		?>
							   			<input type="text" name="subtype<?php echo $i; ?>[]" value="<?php echo $subtname; ?>" maxlength="100" onkeypress="TextValidate()" />
							   			<input type="hidden" name="subtypeid<?php echo $i; ?>[]" value="<?php echo $subtid; ?>"/>		   		
							   		</div>			     
							     </div>		
						     <?php }?>
					    	 <div id="subtype<?php echo $i?>"></div>
					    	 <div class="details_item_line">
					    	 	 <div class="form_left_title left"></div>
						    	 <div class="form_right_e_input left add_sub_file_btn">
						   		 <span onclick="addsubtype('subtype<?php echo $i?>',<?php echo $i?>)" href="#"><?php echo $html->image('list-add.png')?></span>&nbsp;
								 <span onclick="removesubtype('subtype<?php echo $i?>')" href="#"><?php echo $html->image('list-remove.png')?></span> 
						    	 </div>
					    	 </div>
					    </div>
				    </div> 			    		  
				</div>
			</div>
		</div>
		<?php }?>
		<div class="details_item_line edit_form_btn">
            <div class="details_item">
            	<div class="form_left_title left"></div>
                <div class="form_add_submit left">                              	             	
            	<?php echo $form->submit(__('Save',true)) ?>    
            	<?php  echo $form->hidden('Talstack.id'); ?>          	           	
                </div>
            </div>
        </div>	
		</form>		 
	</div>
</div>
<script>
var webpath=$("#getpath").attr('href');
$(document).ready(function() {
	$("#TalstackTname").keyup(function() {    		
		var pname=this.value;
		if(pname.trim()!=""){
   			var pnames=$("#pname").html();
   			if(pnames!=pname){
	   			var urlpath=webpath+'types/checktalname/'+encodeURIComponent(pname);
				$.ajax({     	   
			        url: urlpath, 
			        success:function(data){
			        	if(data=="1")
			        	{
			        		$("#telstacktnamemessage").css('display','block');
			        		$("#telstacktnamemessage").html('项目名称已存在');
			        	}else{
			        		$("#telstacktnamemessage").css('display','none');
			        		$("#telstacktnamemessage").html('请输入项目名称');
			        	}
			        }
			    });
		    }else{
		    	$("#telstacktnamemessage").css('display','none');
			    $("#telstacktnamemessage").html('请输入项目名称');
		    }
	    }else{
	    	$("#telstacktnamemessage").css('display','block');
	    	$("#telstacktnamemessage").html('请输入项目名称');
	    }
    });
});
function checksave()
{
	if($("#telstacktnamemessage").css('display')=="block"){
		return false;
	}
	if($("#TalstackTname").val().trim() == ''){
		$("#telstacktnamemessage").css('display','block');
		return false;
	}else{
		$("#telstacktnamemessage").css('display','none');
	}
	if($("#TalstackGov").val().trim() == ''){
		$("#talstacktypemessage").css('display','block');
		return false;
	}else{
		$("#talstacktypemessage").css('display','none');
	}
}
function addsubtype(id,i) {
	var thenew= document.createElement('div');
	thenew.innerHTML ='<div class="details_item_line"><div class="form_left_title left">三级项目：</div><div class="form_right_e_input left"><input type="text" name="subtype'+i+'[]" maxlength="100" onkeypress="TextValidate()" /></div></div>';
	document.getElementById(id).appendChild(thenew);
	return false;
}
function removesubtype(id) {
	var child=document.getElementById(id).lastChild;
	if(child){
		document.getElementById(id).removeChild(child);
	}
	return false;
}
</script>